package hystrix.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import hystrix.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/hystrix/")
@DefaultProperties(defaultFallback = "defaultFallback")
public class TestController {

    @Autowired
    private OrderService orderService;

    @GetMapping("ok")
    public String getOk() {
        return orderService.getResultOk();
    }


    @GetMapping("out")
    @HystrixCommand
    public String getOut() throws InterruptedException {
        int i = 10/0;
        return orderService.getResultTimeOut();
    }


    public String defaultFallback(){
        return "this this a default fallback method....";
    }
}
